package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.controller.es.EsUnService;
import com.ruoyi.system.controller.es.dto.EsSearch;
import com.ruoyi.system.domain.vo.web.WebFyInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FyInfoMapper;
import com.ruoyi.system.domain.FyInfo;
import com.ruoyi.system.service.IFyInfoService;

/**
 * 资讯Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Service
public class FyInfoServiceImpl implements IFyInfoService
{
    @Autowired
    private FyInfoMapper fyInfoMapper;
    @Autowired
    private EsUnService esUnService;
    /**
     * 查询资讯
     *
     * @param infoId 资讯主键
     * @return 资讯
     */
    @Override
    public FyInfo selectFyInfoByInfoId(Long infoId)
    {
        return fyInfoMapper.selectFyInfoByInfoId(infoId);
    }

    /**
     * 查询资讯列表
     *
     * @param fyInfo 资讯
     * @return 资讯
     */
    @Override
    public List<FyInfo> selectFyInfoList(FyInfo fyInfo)
    {
        return fyInfoMapper.selectFyInfoList(fyInfo);
    }

    @Override
    public List<WebFyInfoVo> selectWebInfoList(String infoTitle) {
        return fyInfoMapper.selectWebInfoList(infoTitle);
    }

    /**
     * 新增资讯
     *
     * @param fyInfo 资讯
     * @return 结果
     */
    @Override
    public int insertFyInfo(FyInfo fyInfo)
    {
        fyInfo.setIsDelete(0l);
        fyInfo.setCreateTime(DateUtils.getNowDate());
        return fyInfoMapper.insertFyInfo(fyInfo);
    }

    /**
     * 修改资讯
     *
     * @param fyInfo 资讯
     * @return 结果
     */
    @Override
    public int updateFyInfo(FyInfo fyInfo)
    {
        fyInfo.setUpdateTime(DateUtils.getNowDate());
        return fyInfoMapper.updateFyInfo(fyInfo);
    }

    /**
     * 批量删除资讯
     *
     * @param infoIds 需要删除的资讯主键
     * @return 结果
     */
    @Override
    public int deleteFyInfoByInfoIds(Long[] infoIds)
    {
        for (Long l:infoIds){
            FyInfo fyInfo=new FyInfo();
            fyInfo.setInfoId(l);
            fyInfo.setIsDelete(1l);
            fyInfoMapper.updateFyInfo(fyInfo);
            EsSearch esSearch=new EsSearch();
            esSearch.setId(fyInfo.getInfoId());
            esSearch.setLanmu("资讯");
            esSearch.setLanmuId(5);
            esUnService.delete(esSearch);
        }
        return 1;
    }

    /**
     * 删除资讯信息
     *
     * @param infoId 资讯主键
     * @return 结果
     */
    @Override
    public int deleteFyInfoByInfoId(Long infoId)
    {
        return fyInfoMapper.deleteFyInfoByInfoId(infoId);
    }
}
